package cn.itcast.utils;


import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/*解决实体管理器工厂的浪费资源和耗时问题
*
* 通过静态代码块  在程序加载时 创建一个公共的工厂对象*/
public class JpaUtils {
   private static EntityManagerFactory factory ;

    static{
        factory = Persistence.createEntityManagerFactory("myjpa");
    }

    public static EntityManager getEntityManager(){
        return factory.createEntityManager();
    }

}
